//
//  UITextField+Category.m
//  MKDriver
//
//  Created by song zhang on 2019/3/26.
//  Copyright © 2019年 song zhang. All rights reserved.
//

#import "UITextField+Category.h"

@implementation UITextField (Category)
+(UITextField *)creatTextField:(CGRect)frame text:(NSString *)text placeholder:(NSString *)placeholder textColor:(UIColor *)textColor textAlignment:(NSTextAlignment)textAlignment font:(UIFont *)font borderStyle:(UITextBorderStyle)borderStyle clearsOnBeginEditing:(BOOL)clearsOnBeginEditing onView:(UIView *)view
{
    UITextField *textField = [[UITextField alloc] initWithFrame:frame];
    textField.text = text;
    textField.placeholder = placeholder;
    textField.textColor = textColor;
    textField.textAlignment = textAlignment;
    textField.font = font;
    textField.borderStyle = borderStyle;
    textField.clearsOnBeginEditing = clearsOnBeginEditing;
    [view addSubview:textField];
    return textField;
}

+(UITextField *)creatTextField:(CGRect)frame text:(NSString *)text placeholder:(NSString *)placeholder textColor:(UIColor *)textColor textAlignment:(NSTextAlignment)textAlignment font:(UIFont *)font borderStyle:(UITextBorderStyle)borderStyle clearsOnBeginEditing:(BOOL)clearsOnBeginEditing onView:(UIView *)view placeholderTextColor:(UIColor *)placeholderTextColor placeholderFont:(UIFont *)placeholderFont
{
    UITextField *textField = [[UITextField alloc] initWithFrame:frame];
    textField.text = text;
    textField.placeholder = placeholder;
    textField.textColor = textColor;
    textField.textAlignment = textAlignment;
    textField.font = font;
    textField.borderStyle = borderStyle;
    textField.clearsOnBeginEditing = clearsOnBeginEditing;
    [view addSubview:textField];
    NSMutableAttributedString *placeholderString = [[NSMutableAttributedString alloc] initWithString:placeholder attributes:@{NSForegroundColorAttributeName:placeholderTextColor,NSFontAttributeName:placeholderFont}];
    textField.attributedPlaceholder = placeholderString;
    return textField;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    
    if (action == @selector(paste:)) {
        return NO;
    }//禁止粘贴

    if (action == @selector(select:)) {
        return NO;
    }// 禁止选择
    if (action == @selector(selectAll:)) {
        return NO;
    }// 禁止全选
    if (action == @selector(captureTextFromCamera:)) {
//        HLFileLog(@"-- %s", action);
        return NO;
    }
            
    return [super canPerformAction:action withSender:sender];
}
@end
